package negocio;

import java.io.Serializable;


import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import beans.ComisionMozoVO;

@Entity
@Table(name="comisiones")
public class ComisionMozo implements Serializable 
{
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private ComisionMozoID id;
	
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="id_dni", referencedColumnName="id_dni", insertable=false , updatable=false)
	private Mozo mozo;
	
	@Column(name="comision")
	private float comision;

	public ComisionMozoID getId() {
		return id;
	}

	public void setId(ComisionMozoID id) {
		this.id = id;
	}

	public Mozo getMozo() {
		return mozo;
	}

	public void setMozo(Mozo mozo) {
		this.mozo = mozo;
	}

	public float getComision() {
		return comision;
	}

	public void setComision(float comision) {
		this.comision = comision;
	}
	
	public ComisionMozoVO getVO()
	{
		ComisionMozoVO cmVO = new ComisionMozoVO();
		cmVO.setComision(getComision());
		cmVO.setId(getId().getVO());
		cmVO.setMozo(getMozo().getVO());
		
		return cmVO;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(comision);
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((mozo == null) ? 0 : mozo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ComisionMozo other = (ComisionMozo) obj;
		if (Float.floatToIntBits(comision) != Float
				.floatToIntBits(other.comision))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (mozo == null) {
			if (other.mozo != null)
				return false;
		} else if (!mozo.equals(other.mozo))
			return false;
		return true;
	}
	
	
	
	
}
